package cn.jit.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.sun.xml.internal.ws.api.pipe.Tube;

import cn.jit.dao.QuestionDao;
import cn.jit.dao.UserDao;
import cn.jit.po.Question;
import cn.jit.po.QuestionVo;
import cn.jit.service.QuestionService;

@Service("questionService")
public class QuestionServiceImpl implements QuestionService{
	
	@Resource
    private QuestionDao questionDao;

	@Override
	public List<Question> getQuestions(Question question) {
		Map<String, Object> params = new HashMap<String,Object>();
		params.put("questionId", question.getQuestionId());
		params.put("questionType", question.getQuestionType());
		params.put("maxLimit", 10);
		return questionDao.getQuestions(params);
	}

	@Override
	public List<Question> getQuestions(Question question, int limit) {
		Map<String, Object> params = new HashMap<String,Object>();
		params.put("questionId", question.getQuestionId());
		params.put("questionType", question.getQuestionType());
		params.put("maxLimit", limit);
		return questionDao.getQuestions(params);
	}

	@Override
	public List<Question> getAllQuestions(Question question) {
		Map<String, Object> params = new HashMap<String,Object>();
		params.put("questionId", question.getQuestionId());
		params.put("questionType", question.getQuestionType());
		return questionDao.getQuestions(params);
	}

	@Override
	public Boolean addBatchQuestion(List<QuestionVo> questionVos) {
		if (questionDao.addBatchQuestion(questionVos) == questionVos.size() ) {
			return true;
		}
		
		return false;
	}

	@Override
	public Question getOneQuestion(Question question) {
		Map<String, Object> params = new HashMap<String,Object>();
		params.put("questionId", question.getQuestionId());
		params.put("questionType", question.getQuestionType());
		return questionDao.getOneQuestion(params);
	}
	
	@Override
	public Boolean addOneQuestion(Question question) {
		int result = questionDao.addOneQuestion(question);
		if (result > 0) {
			return true;
		}
		return false;
	}
		
}
